//https://leetcode.cn/problems/jump-game/submissions/574425333/

class Solution {
public:
    bool canJump(vector<int>& nums) {
        const int N = 1e4 + 10;
        bool vis[N] = { 0 };
        int n = nums.size();

        queue<int> q;
        q.push(0);
        vis[0] = true;
        while (q.size())
        {
            int now = q.front();
            q.pop();
            if (now == n - 1)return true;
            for (int x = now + 1; x <= min(now + nums[now], n - 1); x++)
            {
                if (vis[x])continue;
                vis[x] = true;
                q.push(x);
                if (x == n - 1)return true;
            }
        }
        return vis[n - 1];
    }
};